<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>kafka 消费者 | Oliver知识收集站</title>
    <meta name="generator" content="VuePress 1.9.7">
    
    <meta name="description" content="享受着互联网广泛知识，并加以记录，日积月累让它成为一个档案处！">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/oliver-vuepress/assets/css/0.styles.4ea20d86.css" as="style"><link rel="preload" href="/oliver-vuepress/assets/js/app.c21e6ffc.js" as="script"><link rel="preload" href="/oliver-vuepress/assets/js/3.6dd9a2a1.js" as="script"><link rel="preload" href="/oliver-vuepress/assets/js/1.898920d0.js" as="script"><link rel="preload" href="/oliver-vuepress/assets/js/41.c0d5b947.js" as="script"><link rel="prefetch" href="/oliver-vuepress/assets/js/10.41b2bf91.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/11.a95c117d.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/12.8607f0e1.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/13.a52d6846.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/14.249b4e52.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/15.d458d12e.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/16.ba334206.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/17.1b91c9fa.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/18.e2ea2eb5.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/19.bf0e2553.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/20.268bd174.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/21.cd1bbed5.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/22.da4bc7f7.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/23.12f0c72f.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/24.b7886742.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/25.6e71af85.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/26.5c127243.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/27.e98fd8bf.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/28.ce83b09c.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/29.50398f0f.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/30.05e1339c.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/31.ef4b13fb.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/32.ba5f8351.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/33.3902db0a.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/34.36a05884.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/35.87215872.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/36.db360c58.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/37.402e5374.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/38.c9228dd8.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/39.72ba5d1f.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/4.7bb03d47.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/40.7e7949bf.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/42.d9984467.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/43.e6a43668.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/44.10d7fe47.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/45.f692ec2d.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/46.9b920343.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/47.8e3d94f9.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/48.7d356e5b.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/49.b0df6271.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/5.1fa544da.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/50.805e1466.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/51.1b31d40e.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/52.44e69a41.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/53.da1def53.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/54.6569f7db.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/55.5fc3de47.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/56.da649377.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/57.6ff15ed4.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/58.a62f6424.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/59.f68ae517.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/6.f5bd8e9b.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/60.dda416bc.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/61.4e0c719f.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/62.8c5ef01e.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/63.7089eb8b.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/64.b5ec150d.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/65.6720cda4.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/66.4ee90e29.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/67.cc4b0c6d.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/7.d5950c53.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/8.382fb3a5.js"><link rel="prefetch" href="/oliver-vuepress/assets/js/9.d593f4c1.js">
    <link rel="stylesheet" href="/oliver-vuepress/assets/css/0.styles.4ea20d86.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-130b300a><div data-v-130b300a><div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-130b300a data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>Oliver知识收集站</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>享受着互联网广泛知识，并加以记录，日积月累让它成为一个档案处！</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>oliver.shi</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-130b300a><header class="navbar" data-v-130b300a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/oliver-vuepress/" class="home-link router-link-active"><!----> <span class="site-name">Oliver知识收集站</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/oliver-vuepress/" class="nav-link"><i class="undefined"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      Java
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/basics/" class="nav-link"><i class="undefined"></i>
  基础
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/concurrent/" class="nav-link"><i class="undefined"></i>
  并发
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/jvm/jvm.html" class="nav-link"><i class="undefined"></i>
  JVM
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/other/" class="nav-link"><i class="undefined"></i>
  杂
</a></li></ul></div></div><div class="nav-item"><a href="/oliver-vuepress/articles/spring/first.html" class="nav-link"><i class="undefined"></i>
  Spring
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      中间件
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/redis/redis.html" class="nav-link"><i class="undefined"></i>
  Redis
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/kafka/framework.html" class="nav-link"><i class="undefined"></i>
  Kafka
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/zookeeper.html" class="nav-link"><i class="undefined"></i>
  Zookeeper
</a></li></ul></div></div><div class="nav-item"><a href="/oliver-vuepress/articles/algorithm/" class="nav-link"><i class="undefined"></i>
  算法
</a></div><div class="nav-item"><a href="/oliver-vuepress/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      收集站
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/article/first.html" class="nav-link"><i class="undefined"></i>
  技术好文
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/book/first.html" class="nav-link"><i class="undefined"></i>
  书籍
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/assembly/first.html" class="nav-link"><i class="undefined"></i>
  优秀开发组件
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/software/first.html" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/plugin/first.html" class="nav-link"><i class="undefined"></i>
  插件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-130b300a></div> <aside class="sidebar" data-v-130b300a><div class="personal-info-wrapper" data-v-39576ba9 data-v-130b300a><!----> <h3 class="name" data-v-39576ba9>
    oliver.shi
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>52</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>6</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/oliver-vuepress/" class="nav-link"><i class="undefined"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      Java
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/basics/" class="nav-link"><i class="undefined"></i>
  基础
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/concurrent/" class="nav-link"><i class="undefined"></i>
  并发
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/jvm/jvm.html" class="nav-link"><i class="undefined"></i>
  JVM
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/java/other/" class="nav-link"><i class="undefined"></i>
  杂
</a></li></ul></div></div><div class="nav-item"><a href="/oliver-vuepress/articles/spring/first.html" class="nav-link"><i class="undefined"></i>
  Spring
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      中间件
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/redis/redis.html" class="nav-link"><i class="undefined"></i>
  Redis
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/kafka/framework.html" class="nav-link"><i class="undefined"></i>
  Kafka
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/middleware/zookeeper.html" class="nav-link"><i class="undefined"></i>
  Zookeeper
</a></li></ul></div></div><div class="nav-item"><a href="/oliver-vuepress/articles/algorithm/" class="nav-link"><i class="undefined"></i>
  算法
</a></div><div class="nav-item"><a href="/oliver-vuepress/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="undefined"></i>
      收集站
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/article/first.html" class="nav-link"><i class="undefined"></i>
  技术好文
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/book/first.html" class="nav-link"><i class="undefined"></i>
  书籍
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/assembly/first.html" class="nav-link"><i class="undefined"></i>
  优秀开发组件
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/software/first.html" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/oliver-vuepress/articles/collect/plugin/first.html" class="nav-link"><i class="undefined"></i>
  插件
</a></li></ul></div></div> <!----></nav> <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Kafka</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/oliver-vuepress/articles/middleware/kafka/framework.html" class="sidebar-link">kafka 架构体系</a></li><li><a href="/oliver-vuepress/articles/middleware/kafka/producer.html" class="sidebar-link">kafka 生产者</a></li><li><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html" aria-current="page" class="active sidebar-link">kafka 消费者</a></li><li><a href="/oliver-vuepress/articles/middleware/kafka/log.html" class="sidebar-link">kafka 日志</a></li><li><a href="/oliver-vuepress/articles/middleware/kafka/why-fast.html" class="sidebar-link">kafka 为什么快</a></li><li><a href="/oliver-vuepress/articles/middleware/kafka/application.html" class="sidebar-link">kafka的优缺点&amp; 应用场景</a></li></ul></section></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>kafka 消费者</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>oliver.shi</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-130b300a><main class="page"><section><div class="page-title"><h1 class="title">kafka 消费者</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>oliver.shi</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>12/5/2021</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>消息队列</span><span class="tag-item" data-v-f875f3fc>kafka</span></i></div></div> <div class="theme-reco-content content__default"><h2 id="消费者-消费者组"><a href="#消费者-消费者组" class="header-anchor">#</a> 消费者 &amp; 消费者组</h2> <p><strong>消费者简介</strong>
消费者 通过 订阅主题，进行消费消息。消费者自己维护这消费消息的偏移量，存储在 kafka 主题 <code>__consumer_offsets</code>   中
消费者 也提供将自己的偏移量存储在 <code>Zookeeper</code>  中,  需要设置 <code>置offset.storage=zookeeper</code>
消费者 可以被分配一个主题的多个分区进行消费，同一个分区内的消息，能保证顺序消费
<strong>注：</strong> Zookeeper 不适合高并发</p> <p><strong>消费者组</strong>
通过 设置 同一个 <code>group_id</code>  将 多个消费者 加入同一个消费者组
消费组能均衡的给消费者分配一个主题中的分区，确保一个主题的分区在该消费组中 只能分配给一个消费者进行消费</p> <p><strong>kafka广播和点对点模式</strong></p> <ul><li>kafka中的广播模式：即 设定 多个消费组，不同的消费组中的消费者 能同时消费 同一个主题</li> <li>点对点模式：即 只设定一个消费组进行消费指定的主题</li></ul> <img src="/oliver-vuepress/middleware/kafka/consumer1.jpg" alt="foo"> <p><strong>如何提高消费组的消费能力？</strong>
可以通过 添加消费者来进行增加并发的消费能力，前提 主题分区数 &gt;= 消费者数量
当消费者数量大于 分区数时 则是对消费能力的浪费</p> <img src="/oliver-vuepress/middleware/kafka/consumer2.jpg" alt="foo"> <h2 id="消费者的心跳机制"><a href="#消费者的心跳机制" class="header-anchor">#</a> 消费者的心跳机制</h2> <blockquote><p>Kafka 的心跳是 Kafka Consumer 和 Broker 之间的健康检查，只有当 Broker Coordinator 正常时，Consumer 才会发送心跳。</p></blockquote> <p><strong>消费者核心心跳参数</strong></p> <ul><li>session.timeout.ms：  默认值是：10000 （10s）【Consumer Seesion 过期时间 - 即心跳超时时间】</li> <li>heartbeat.interval.ms： 默认值是：3000 （3s） 【心跳间隔 - 每几秒向协调者进行发送心跳】</li> <li>max.poll.interval.ms:   默认值是：300000 （5分钟）【指定consumer两次poll的最大时间间隔】</li></ul> <p><strong>上面的参数</strong> <code>session.timeout.ms</code>   和 <code>heartbeat.interval.ms</code>   在 10 秒的超时时间内，每3秒触发一次心跳 ， 一般来说 尽可能缩短心跳，以及 尽可能的延长超时时间，这样能够在指定时间内竟可能的多长时间心跳检测，每次心跳操作可能会存在高负载的延时问题 或 心跳丢失等。所以尽可能的合理分配两个参数，让心跳能尽可能的多。但太频繁的心跳，也会影响性能。</p> <h3 id="broker端的检测机制"><a href="#broker端的检测机制" class="header-anchor">#</a> Broker端的检测机制</h3> <p>主要通过： session.timeout.ms</p> <blockquote><p>Broker 处理心跳的逻辑：如果心跳超期， broker coordinator（协调者）会把消费者从 group 中移除，并触发 rebalance。</p></blockquote> <h3 id="consumer端的检测机制"><a href="#consumer端的检测机制" class="header-anchor">#</a> Consumer端的检测机制</h3> <p>主要通过： session.timeout.ms  、max.poll.interval.ms</p> <ul><li>如果消费者发现自身心跳超期，会标记 broker 协调者 不能用，并堵塞心跳 【 session.timeout.ms】</li> <li>如果消费者发现自身 poll 消息超过 指定时间，则任务消费者丧失能力，主动 告知 broker 离开消费组</li></ul> <p>::注:: 消费者心跳超时后，不管是如何发生的超时，都会触发 <code>rebalance</code>  重平衡操作  <strong>(后续详解)</strong></p> <h2 id="位移提交"><a href="#位移提交" class="header-anchor">#</a> 位移提交</h2> <blockquote><p>Consumer 需要向Kafka记录自己的位移数据，这个汇报过程称为 提交位移(CommittingOffsets)<br>
Consumer 需要为分配给它的每个分区提交各自的位移数据<br>
位移提交的由Consumer 端负责的，Kafka只负责保管 在 <code>__consumer_offsets</code>  主题中</p></blockquote> <p><strong>位移提交可以分为：</strong></p> <ul><li>自动提交</li> <li>手动提交
<ul><li>同步提交</li> <li>异步提交</li></ul></li></ul> <h3 id="自动提交"><a href="#自动提交" class="header-anchor">#</a> 自动提交</h3> <p><strong>核心参数</strong></p> <ul><li>开启自动提交： enable.auto.commit=true</li> <li>配置自动提交间隔：Consumer端： auto.commit.interval.ms ，默认 5s</li></ul> <p><strong>自动提交有什么好处？</strong></p> <blockquote><p>Kafka会保证在开始调用poll方法时，提交上次poll返回的所有消息, 因此自动提交不会出现消息丢失</p></blockquote> <p><strong>自动提交又会带来什么问题？</strong></p> <blockquote><p>可能会出现重复消费的问题</p></blockquote> <p>可能会触发的案例：</p> <ul><li>Consumer 每 5s 提交 offset</li> <li>假设提交 offset 后的 3s 发生了 Rebalance</li> <li>Rebalance 之后的所有 Consumer 从上一次提交的 offset 处继续消费</li> <li>因此 Rebalance 发生前 3s 的消息会被重复消费</li></ul> <h3 id="手动提交"><a href="#手动提交" class="header-anchor">#</a> 手动提交</h3> <p>只需要将 参数  <code>enable.auto.commit = false</code>  即 将提交方式设置为 手动提交</p> <p>手动提交分为：</p> <ul><li>同步提交  <code>consumer.commitSync()</code><br>
同步提交，会让 Consumer 处于堵塞状态，会影响 TPS。可以通过选择拉长提交间隔 提高性能 （和自动提交类似，降低了提交的频率，则会触发消息重复消息的问题）</li></ul> <div class="language-java extra-class"><pre class="language-java"><code><span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token class-name">ConsumerRecords</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> records <span class="token operator">=</span>
	consumer<span class="token punctuation">.</span><span class="token function">poll</span><span class="token punctuation">(</span><span class="token class-name">Duration</span><span class="token punctuation">.</span><span class="token function">ofSeconds</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token function">process</span><span class="token punctuation">(</span>records<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 处理消息</span>
	<span class="token keyword">try</span> <span class="token punctuation">{</span>
		consumer<span class="token punctuation">.</span><span class="token function">commitSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">CommitFailedException</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token function">handle</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 处理提交失败异常</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ul><li>异步提交  <code>consumer.commitAsync()</code></li></ul> <p>由下面代码可见：当异步操作是，发生异常后，服务实现重试操作</p> <div class="language-Java extra-class"><pre class="language-java"><code>
<span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token class-name">ConsumerRecords</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> records <span class="token operator">=</span> consumer<span class="token punctuation">.</span><span class="token function">poll</span><span class="token punctuation">(</span><span class="token number">3_000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token function">process</span><span class="token punctuation">(</span>records<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 处理消息</span>
	consumer<span class="token punctuation">.</span><span class="token function">commitAsync</span><span class="token punctuation">(</span><span class="token punctuation">(</span>offsets<span class="token punctuation">,</span> exception<span class="token punctuation">)</span> <span class="token operator">-&gt;</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span>exception <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token function">handle</span><span class="token punctuation">(</span>exception<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><p>可以使用 <code>try ... catch</code>  的方式在不影响性能的情况下，保证提交的可靠性。毕竟正常情况失败的可能性比较少，如果大批量都失败了，可能是服务出现了问题</p> <p><strong>优化处理逻辑</strong></p> <div class="language-Java extra-class"><pre class="language-java"><code><span class="token keyword">try</span> <span class="token punctuation">{</span>
	<span class="token keyword">while</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token class-name">ConsumerRecords</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">,</span> <span class="token class-name">String</span><span class="token punctuation">&gt;</span></span> records <span class="token operator">=</span>
		consumer<span class="token punctuation">.</span><span class="token function">poll</span><span class="token punctuation">(</span><span class="token class-name">Duration</span><span class="token punctuation">.</span><span class="token function">ofSeconds</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token function">process</span><span class="token punctuation">(</span>records<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 处理消息</span>
		<span class="token function">commitAysnc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 使用异步提交规避阻塞</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span> <span class="token keyword">catch</span><span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token function">handle</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 处理异常</span>
<span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
	<span class="token keyword">try</span> <span class="token punctuation">{</span>
		consumer<span class="token punctuation">.</span><span class="token function">commitSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 最后一次提交使用同步阻塞式提交</span>
	<span class="token punctuation">}</span> <span class="token keyword">finally</span> <span class="token punctuation">{</span>
		consumer<span class="token punctuation">.</span><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><ul><li>相关提交操作案例：<a href="https://www.cnblogs.com/biehongli/p/14105658.html" target="_blank" rel="noopener noreferrer">Kafka的消费者提交方式手动同步提交、和异步提交 - 别先生 - 博客园<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <p><strong>重点思考：</strong>  我们需要思考  如何即能解决 消息丢失 和 重复消费 呢？</p> <h2 id="再-重均衡-reblance"><a href="#再-重均衡-reblance" class="header-anchor">#</a> 再/重均衡 reblance</h2> <blockquote><p>重平衡其实就是一个协议，它规定了如何让消费者组下的所有消费者来分配topic中的每一个分区。</p></blockquote> <p><strong>重均衡的触发条件：</strong></p> <ol><li>消费者组内成员发生变更，这个变更包括了增加和减少消费者，比如消费者宕机退出消费组。</li> <li>主题的分区数发生变更，kafka目前只支持增加分区，当增加的时候就会触发重平衡</li> <li>订阅的主题发生变化，当消费者组使用正则表达式订阅主题，而恰好又新建了对应的主题，就 会触发重平衡</li></ol> <p><strong>为什么说重平衡为人诟病呢？</strong></p> <blockquote><p>因为重平衡过程中，消费者无法从kafka消费消息，这对kafka的TPS 影响极大，而如果kafka集内节点较多，比如数百个，那重平衡可能会耗时极多。数分钟到数小时都有可能，而这段时间kafka基本处于不可用状态。**</p></blockquote> <blockquote><p><strong>要说完全避免重平衡，是不可能，所以我们需要保证尽力避免消费者故障</strong></p></blockquote> <p>部分情况，可能是负责过高 没来得急心跳 或者网络堵塞 或者是自身消费处理能力不够
避免重平衡相关的配置：</p> <ul><li>session.timout.ms：默认10秒  控制心跳超时时间</li> <li>heartbeat.interval.ms： 默认3秒 控制心跳发送频率 (常见的可能网络抖动 或者 网络延迟等可能 心跳的超时时间要大于 心跳发送频率)</li> <li>max.poll.interval.ms :  控制poll的间隔。 指定consumer两次poll的最大时间间隔（默认5分钟），如果超过了该间隔consumer client会主动向coordinator发起LeaveGroup请求，触发rebalance</li> <li>max-poll-records:  150 每次拉取的数据条数 (默认500条）</li></ul> <p><strong>总结</strong></p> <ul><li>在心跳测：我们可以尽可能的提高 超时时间  <code>session.timout.ms</code> 和 加快心跳发送频率（heartbeat.interval.ms），让充分多的进行心跳，减少超时的可能</li> <li>在消费能力侧：通过控制poll的间隔 <code>max.poll.interval.ms</code>  和 每次拉取的条数 <code>max-poll-records</code>  竟可能的在指定的时间内最大化的的保证任务能完成的数量，不要因为每次拉取的数据过多，导致消费不完，而导致的 reblance</li> <li>自身处理能力侧：可以优化业务逻辑代码 或 使用多线程消费 来提高消费侧的能力，避免一次拉取消费不完的情况</li></ul> <h2 id="消费组内分区分配策略"><a href="#消费组内分区分配策略" class="header-anchor">#</a> 消费组内分区分配策略</h2> <p>三种分配策略：</p> <ul><li>RangeAssignor  【默认的分配策略】</li> <li>RoundRobinAssignor</li> <li>StickyAssignor</li> <li>自定义分配策略：通过实现 <code>org.apache.kafka.clients.consumer.internals.PartitionAssignor</code>  接口</li></ul> <h3 id="rangeassignor"><a href="#rangeassignor" class="header-anchor">#</a> RangeAssignor</h3> <blockquote><p>RangeAssignor对每个Topic进行独立的分区分配。对于每一个Topic，首先对分区按照分区ID进行数值排序，然后订阅这个Topic的消费组的消费者再进行字典排序，之后尽量均衡的将分区分配给消费者。这里只能是尽量均衡，因为分区数可能无法被消费者数量整除，那么有一些消费者就会多分配到一些分区。<br> <strong>总结:</strong> 首先通过  分区数/消费者 数量进行平均分配。多余的分区数进行顺序挨个往下分配</p></blockquote> <img src="/oliver-vuepress/middleware/kafka/consumer3.jpg" alt="foo"> <p><strong>存在的问题</strong></p> <blockquote><p>当主题数增加后，可能会造成 字典序靠前的消费组中的消费者比较“贪婪”  即 靠前的消费者 需要消费更的分区数据</p></blockquote> <img src="/oliver-vuepress/middleware/kafka/consumer4.jpg" alt="foo"> <h3 id="roundrobinassignor"><a href="#roundrobinassignor" class="header-anchor">#</a> RoundRobinAssignor</h3> <blockquote><p>轮询消费：分配策略是将消费组内订阅的所有Topic的分区及所有消费者进行排序后尽量均衡的分配</p></blockquote> <img src="/oliver-vuepress/middleware/kafka/consumer5.jpg" alt="foo"> <h3 id="stickyassignor"><a href="#stickyassignor" class="header-anchor">#</a> StickyAssignor</h3> <blockquote><p>个人理解，后续的分配会更具上过一次分配的结果，进行做间隔分配（往后跳过）几个消费者进行分配</p></blockquote> <h2 id="序列化器"><a href="#序列化器" class="header-anchor">#</a> 序列化器</h2> <blockquote><p>Kafka的broker中所有的消息都是字节数组，消费者获取到消息之后，需要先对消息进行反序列化处理，然后才能交给用户程序消费处理。</p></blockquote> <p><strong>自定义序列化器</strong>： 可以通过现 <code>org.apache.kafka.common.serialization.Deserializer&lt;T&gt;</code> 接口</p> <h2 id="拦截器"><a href="#拦截器" class="header-anchor">#</a> 拦截器</h2> <blockquote><p>消费者在拉取了分区消息之后，要首先经过反序列化器对key和value进行反序列化处理。<br>
处理完之后，如果消费端设置了拦截器，则需要经过拦截器的处理之后，才能返回给消费者应用程序进行处理。<br>
::注:: 可以使用多个拦截器，拦截器按顺序执行的</p></blockquote> <p><strong>自定义消息拦截器</strong> 可以通过实现 <code>org.apache.kafka.clients.consumer.ConsumerInterceptor&lt;K, V&gt;</code> 接口</p> <p><strong>常见的拦截器功能：</strong></p> <ul><li>允许拦截甚至更改消费者接收到的消息，一般用于定制的监控、日志处理等</li></ul> <div class="language-Java extra-class"><pre class="language-java"><code><span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">ConsumerInterceptor</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">K</span><span class="token punctuation">,</span> <span class="token class-name">V</span><span class="token punctuation">&gt;</span></span> <span class="token keyword">extends</span> <span class="token class-name">Configurable</span> <span class="token punctuation">{</span>

	<span class="token comment">/**
	*
	* 该方法在poll方法返回之前调用。调用结束后poll方法就返回消息了。
	*
	* 该方法可以修改消费者消息，返回新的消息。拦截器可以过滤收到的消息或生成新的消息。
	* 如果有多个拦截器，则该方法按照KafkaConsumer的configs中配置的顺序调用。
	*
	* @param records 由上个拦截器返回的由客户端消费的消息。
	*/</span>
	<span class="token keyword">public</span> <span class="token class-name">ConsumerRecords</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">K</span><span class="token punctuation">,</span> <span class="token class-name">V</span><span class="token punctuation">&gt;</span></span> <span class="token function">onConsume</span><span class="token punctuation">(</span><span class="token class-name">ConsumerRecords</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">K</span><span class="token punctuation">,</span> <span class="token class-name">V</span><span class="token punctuation">&gt;</span></span> records<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">/**
	* 当消费者提交偏移量时，调用该方法。
	* 该方法抛出的任何异常调用者都会忽略。
	*/</span>
	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">onCommit</span><span class="token punctuation">(</span><span class="token class-name">Map</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">TopicPartition</span><span class="token punctuation">,</span> <span class="token class-name">OffsetAndMetadata</span><span class="token punctuation">&gt;</span></span> offsets<span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="协调器"><a href="#协调器" class="header-anchor">#</a> 协调器</h2> <ul><li><a href="https://blog.csdn.net/liyiming2017/article/details/82867765" target="_blank" rel="noopener noreferrer">Apache Kafka核心组件和流程-协调器（消费者和组协调器）-设计-原理（入门教程轻松学）_稀有气体的技术博客-CSDN博客_kafka组协调器<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="多线程消费"><a href="#多线程消费" class="header-anchor">#</a> 多线程消费</h2> <ul><li><a href="https://blog.csdn.net/Johnnyz1234/article/details/98318528" target="_blank" rel="noopener noreferrer">正确处理kafka多线程消费的姿势_Johnnie Zhang的专栏-CSDN博客_kafka多线程消费<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://www.cnblogs.com/huxi2b/p/6124937.html" target="_blank" rel="noopener noreferrer">【原创】Kafka Consumer多线程实例 - huxihx - 博客园<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/qq_31289187/article/details/81983017" target="_blank" rel="noopener noreferrer">kafka多线程消费_燕少江湖-CSDN博客_kafka多线程消费同一个topic<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://zhuanlan.zhihu.com/p/144870495?from_voters_page=true" target="_blank" rel="noopener noreferrer">使用两种多线程模式消费kafka数据 - 知乎<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://segmentfault.com/a/1190000018640106" target="_blank" rel="noopener noreferrer">使用多线程增加kafka消费能力 - SegmentFault 思否<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="其他"><a href="#其他" class="header-anchor">#</a> 其他</h2> <ul><li>为什么说 Zookeeper不适合高并发</li></ul></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">4/21/2022, 8:17:59 AM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev"><a href="/oliver-vuepress/articles/middleware/kafka/producer.html" class="prev">
            kafka 生产者
          </a></span> <span class="next"><a href="/oliver-vuepress/articles/middleware/kafka/log.html">
            kafka 日志
          </a></span></p></div> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#消费者-消费者组" class="sidebar-link reco-side-消费者-消费者组" data-v-cb1513f6>消费者 &amp; 消费者组</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#消费者的心跳机制" class="sidebar-link reco-side-消费者的心跳机制" data-v-cb1513f6>消费者的心跳机制</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#broker端的检测机制" class="sidebar-link reco-side-broker端的检测机制" data-v-cb1513f6>Broker端的检测机制</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#consumer端的检测机制" class="sidebar-link reco-side-consumer端的检测机制" data-v-cb1513f6>Consumer端的检测机制</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#位移提交" class="sidebar-link reco-side-位移提交" data-v-cb1513f6>位移提交</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#自动提交" class="sidebar-link reco-side-自动提交" data-v-cb1513f6>自动提交</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#手动提交" class="sidebar-link reco-side-手动提交" data-v-cb1513f6>手动提交</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#再-重均衡-reblance" class="sidebar-link reco-side-再-重均衡-reblance" data-v-cb1513f6>再/重均衡 reblance</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#消费组内分区分配策略" class="sidebar-link reco-side-消费组内分区分配策略" data-v-cb1513f6>消费组内分区分配策略</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#rangeassignor" class="sidebar-link reco-side-rangeassignor" data-v-cb1513f6>RangeAssignor</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#roundrobinassignor" class="sidebar-link reco-side-roundrobinassignor" data-v-cb1513f6>RoundRobinAssignor</a></li><li class="level-3" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#stickyassignor" class="sidebar-link reco-side-stickyassignor" data-v-cb1513f6>StickyAssignor</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#序列化器" class="sidebar-link reco-side-序列化器" data-v-cb1513f6>序列化器</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#拦截器" class="sidebar-link reco-side-拦截器" data-v-cb1513f6>拦截器</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#协调器" class="sidebar-link reco-side-协调器" data-v-cb1513f6>协调器</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#多线程消费" class="sidebar-link reco-side-多线程消费" data-v-cb1513f6>多线程消费</a></li><li class="level-2" data-v-cb1513f6><a href="/oliver-vuepress/articles/middleware/kafka/consumer.html#其他" class="sidebar-link reco-side-其他" data-v-cb1513f6>其他</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/oliver-vuepress/assets/js/app.c21e6ffc.js" defer></script><script src="/oliver-vuepress/assets/js/3.6dd9a2a1.js" defer></script><script src="/oliver-vuepress/assets/js/1.898920d0.js" defer></script><script src="/oliver-vuepress/assets/js/41.c0d5b947.js" defer></script>
  </body>
</html>
